function isIE() {
  if (!!window.ActiveXObject || "ActiveXObject" in window)
    return true;
  else
    return false;
}
var urlhost = "http://jy.sanzhima.cn"
// console.log(window)
// var storage = window.localStorage;
// storage.setItem('uid', '200')
function getparse(url,no) {
  var num
  if(url.indexOf("?")) {
    num = url.indexOf("?")
  }else {
    num = url.indexOf("#")
  }
  var str = url.substr(num + 1)
  var arr = str.split("&")
  var numiud = arr[no].indexOf("=")
  var idid = arr[no].substr(numiud + 1)
  return idid
}
// 时间转换方法
function timeschange (time) {
  var date = new Date(time);
  Y = date.getFullYear() + '-';
  M = (date.getMonth()+1 < 10 ? '0'+(date.getMonth()+1) : date.getMonth()+1) + '-';
  D = date.getDate() + ' ';
  h = date.getHours() + ':';
  m = date.getMinutes() + ':';
  s = date.getSeconds(); 
  console.log(Y+M+D+h+m+s);
  var newdata = Y+M+D+h+m+s
  return newdata
}
// 点击转换样式事件
function clickchange(item,className,activename) {
  if(item.hasClass(activename)) {
    return
  }
  item.parent().find(className).removeClass(activename)
  item.addClass(activename)
}
// 点击加载中事件
function loadingShow () {
  $('body').prepend(  '<div class="globalview">'
 + '<img src="./static/images/loading.gif" class="loading" alt="">'
+'</div>')
}
function loadingHide () {
  $('body').find('.globalview').remove()
}
// 页面箭头导航条
var urllist = {
  'main': '首页',
  'index': '我的',
  'smallClass': '微课',
  'mockTest': '模拟试题',
  'previousQuestions': '往届真题',
  'recruitment': '自主招生',
  'recruitmentss': '单独招生',
  'careerPlanning': '职业规划',
  'message': '消息',
  'schools': '院校大全',
  'major': '专业大全',
  'infotest': '高考资讯',
  'testItem': '试题详情',
  'zhiyuan': '志愿填报',
  'simulation': '志愿智能模拟表',
  'plan': '招生计划',
  'A': '志愿填报推荐院校',
  'last_year': '历年批次',
  'xinli': '心理辅导'
}
var urllist_skip = {
  'main': './index.html',
  'index': './mycenter.html',
  'smallClass': './index.html?index=3',
  'mockTest': './index.html?index=4',
  'previousQuestions': './index.html?index=5',
  'recruitment': './recruitment.html',
  'careerPlanning': './careerPlanning.html',
  'message': '/',
  'schools': '/',
  'major': '/',
  'infotest': '/',
  'testItem': '/',
  'zhiyuan': '/',
  'simulation': '/',
  'plan': '/'
}
// 添加箭头导航条
function ArrowNavigation (item,type) {
  // alert('haha')
  console.log(item)
  var html = ''
  for(var i=0;i<type.length;i++) {
    if(i == type.length-1) {
      html += '<span class="sspan section_div_p_lpan" id="' + urllist_skip[type[i]] + '">' + urllist[type[i]] + '</span>'
    }else {
      html += '<span class="sspan section_div_p_span" id="' + urllist_skip[type[i]] + '">' + urllist[type[i]] + '></span>'
    }
  }
  console.log(html)
  var phtml = '<p class="section_div_p">' + html + '</p>'
  item.prepend(phtml)
  item.on('click', '.sspan', function() {
    var srcskip = $(this).attr('id')
    window.location.href = srcskip
  })
}
// 移除箭头导航条
function removeArrowNavigation () {
  if(!$('.section_div_p')) {
    return
  }
  $('.section_div_p').remove()
}
// ajax请求方法
function packagingAjax (url, data) {
  loadingShow()
  var lalala = ''
  return $.ajax({
    url: urlhost + url,
    type: 'POST',
    data: data,
    header: {},
    success: function (res) {
      if (res.code == 0) {
        loadingHide()
        return res
      } else {
        // 移除加载中样式
        loadingHide()
        return(res.data)
      }
    },
    fail: function () {
      alert('网络有问题')
    }
  })
}
$('body').on('click', '.mobileapp', function() {
  window.location.href = './mobileapp.html'
})
$('body').on('click', '.vipprop', function() {
  window.location.href = './member.html'
})
$('body').on('click', '.headerSwipper_div_iconview', function() {
  window.location.href = './index.html'
})
// 登录点击
if(store.get('uid')) {
  $('body').find('.loginText').hide()
  $('.headerSwipper_div_myicon_icon').css({
    'display': 'block'
  })
  // 修改头像
  $.ajax({
    url: urlhost + '/admin.php/api/index/getUserInfo',
    method: 'POST',
    data: {
      uid: store.get('uid')
    },
    success: function (res) {
      // console.log(res.data.icon)
      $('.headerSwipper_div_myicon').find('img').attr('src',res.data.icon)
    }
  })
  // 鼠标移动到头像事件
  $('.headerSwipper_div_myicon').find('img').mouseenter(
   function () {
     $('.headerSwipper_div_myicon_info').show()
   }
  )
  $('.headerSwipper_div_myicon').mouseleave(
   function () {
     $('.headerSwipper_div_myicon_info').hide()
   }
  )
  $('body').on('click', '.headerSwipper_div_myicon_info_li', function(event) {
   if($(this).index() == 1) {
    event.stopPropagation()
    $('.headerSwipper_div_myicon_icon').css({
      'display': 'none'
    })
    $('.headerSwipper_div_myicon_info').css({
      'display': 'none'
    })
    $('.loginText').css({
      'display': 'inline-block'
    })
    store.remove('uid')
    window.location.href = './index.html'
   }
   if($(this).index() == 0) {
     location.href = './message.html'
   }
  })
  $('.headerSwipper_div_myicon_icon').click(
    function (e) {
      e.stopPropagation()
      window.location.href = './mycenter.html'

    }
  )
}
// $('body').on('click', '.headerSwipper_div_myicon', function() {
//   store.set('uid', '200')
//   $(this).find('.loginText').hide()
//   $('.headerSwipper_div_myicon_icon').css({
//     'display': 'block'
//   })
//   // 鼠标移动到头像事件
//   $('.headerSwipper_div_myicon').find('img').mouseenter(
//     function () {
//       $('.headerSwipper_div_myicon_info').show()
//     }
//   )
//   $('.headerSwipper_div_myicon').mouseleave(
//     function () {
//       $('.headerSwipper_div_myicon_info').hide()
//     }
//   )
//   $('body').on('click', '.headerSwipper_div_myicon_info_li', function(event) {
//     if($(this).index() == 1) {
//     event.stopPropagation()
//     $('.headerSwipper_div_myicon_icon').css({
//       'display': 'none'
//     })
//     $('.headerSwipper_div_myicon_info').css({
//       'display': 'none'
//     })
//     $('.loginText').css({
//       'display': 'inline-block'
//     })
//     store.remove('uid')
//     }
//     if($(this).index() == 0) {
//       location.href = './message.html'
//     }
//   })
// })
$('body').on('click', '.loginText', function() {
  $('body').find('.loginview').show()
})

// 提示弹窗内容
function widowAle (str) {
  var scrollTop = window.pageYOffset
                || document.documentElement.scrollTop
                || document.body.scrollTop
                || 0;
                console.log(scrollTop)
  $('body').prepend('<div class="widowale" style="position: fixed;border-radius:8px;color:#fff;top:50%;left:50%;padding:20px;transform: translate(-50%,-50%);background-color:rgba(0,0,0,0.5);z-index:999;">'+ str +'</div>')
  setTimeout( function() {
    $('body').find('.widowale').remove()
  },1500)
}

// 搜索院校方法
$('body').on('click', '.searchicon_img', function () {
  var school_search = $(this).parent().find('input[type="text"]').val()
  location.href = './schools.html?keyword=' + school_search
})
// 搜索院校方法
$('body').on('keyup', '.inputview_input', function (event) {
  var school_search = $(this).parent().find('input[type="text"]').val()
  if(event.keyCode == 13) {
    location.href = './schools.html?keyword=' + school_search
  }
})
// 登录验证
if(!store.get('uid')) {
  $('body').on('click', '.login_btn', function () {
    var namelogin = $('body').find('input[name="login_name"]').val()
    var namepass = $('body').find('input[name="login_pass"]').val()
    var that = this
    $.ajax({
      url: urlhost + '/admin.php/api/index/index',
      method: 'POST',
      data: {
        username: namelogin,
        card_pws: namepass
      },
      success: function (res) {
        if(res.code == 0) {
          store.set('uid', res.data.uid)
          store.set('info',res.data)
          $(that).parents('.loginview').hide()
          location.reload()
        }else {
          $('body').find('input[name="login_name"]').val('')
          $('body').find('input[name="login_name"]').attr('placeholder',res.msg)
        }
      }
    })
  })
  $('body').on('click', '.no_login_sp', function () {
    location.href = './member.html'
  })
  $('body').on('click', '.login_close', function () {

    $(this).parents('.loginview').hide()
  })
}

// 邮箱更改 middleInfo_span_GE_text_color
$('.footerSwipper').find('.middleInfo_span_GE_text').eq(1).text('hn750jy@126.com')
$('.footerSwipper').find('.middleInfo_span_GE_text_color').text('4000999750')
var availableTags = []
$('.inputview').on('input','#tag',function (e) {
  // console.log(e.target.value)
  var keys = e.target.value
  $.ajax({
    url: urlhost + '/admin.php/api/homepage/pcsearch',
    method: 'POST',
    data: {
      keywords: keys
    },
    success: function (res) {
      // console.log(res)
      var shools = res.data
      var sss = []
      for(var i=0;i<shools.length;i++) {
        sss.push(shools[i].sch_name)
      }
      availableTags = sss
    }
  })
  // console.log(availableTags)
  $( "#tag" ).autocomplete({
    source: availableTags
  });
})


